﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CNav.Domain;
using FluentValidation;

namespace CNav.Business.Validation
{
    public class UserProfileValidator : AbstractValidator<UserProfile>
    {
        public UserProfileValidator()
        {
            RuleFor(u => u.FirstName).NotEmpty().Length(2, 20).WithMessage("The Firstname must be at least 2 characters long.");
            RuleFor(u => u.LastName).NotEmpty().Length(2, 20).WithMessage("The Lastname must be at least 2 characters long.");
            RuleFor(u => u.Email).EmailAddress().WithMessage("Please specify a email address.");
            RuleFor(u => u.PhoneNumber).Must(ValidatorUtils.IsPhone).WithMessage("Please specify a valid phone number.");
            RuleFor(u => u.UserPosition).NotEmpty().Length(6, 20).WithMessage("Please specify user position least 6 characters long.");
        }
    }

    public class UserProfileExValidator : AbstractValidator<UserProfileEx>
    {
        public UserProfileExValidator()
        {
            RuleFor(u => u.FirstName).NotEmpty().Length(2, 20).WithMessage("The Firstname must be at least 2 characters long.");
            RuleFor(u => u.LastName).NotEmpty().Length(2, 20).WithMessage("The Lastname must be at least 2 characters long.");
            RuleFor(u => u.Email).EmailAddress().WithMessage("Please specify a email address.");
            RuleFor(u => u.PhoneNumber).Must(ValidatorUtils.IsPhone).WithMessage("Please specify a valid phone number.");
            RuleFor(u => u.UserPosition).NotEmpty().Length(6, 20).WithMessage("Please specify user position least 6 characters long.");

            RuleFor(u => u.MachineIP).NotEmpty().Length(8, 16).WithMessage("The MachineIP must be at least 8 characters long.");
        }
    }

    public class RegisterUserProfileValidator : AbstractValidator<RegisterUserProfile>
    {
        public RegisterUserProfileValidator()
        {
            RuleFor(u => u.AccountExpireDate)
                .GreaterThan(DateTime.UtcNow)
                .WithMessage("Account expire date must be in the future.");
            RuleFor(u => u.Password).NotEmpty().WithMessage("Please specify a user password.");
            RuleFor(u => u.Password).NotEmpty().Length(6, 20).When(u => string.IsNullOrEmpty(u.Password)).WithMessage("The password must be 6 - 20 characters long.");
            RuleFor(u => u.UserPosition).NotEmpty().Length(6, 20).WithMessage("Please specify user position least 6 characters long.");
        }
    }
}
